home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / TR_NDXSZ.PRG < prev    next >
Text File  |  1990-10-22  |  1KB  |  45 lines

  1. *********
  2. *  TR_NDXSZ.PRG
  3. *
  4. *  by Leonard Zerman and Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. *  Syntax: NDXSIZE( <key size>, <no. of records> )
  9. *  Return: <expN> integer maximum potential number of bytes in index file
  10. *********
  11.  
  12. FUNCTION NDXSIZE
  13. *
  14. PARAMETERS keylen, last_recno
  15. MEMVAR maxitem, b_nodes, node_cnt
  16. PRIVATE maxitem, b_nodes, node_cnt
  17.  
  18. IF last_recno == 0
  19.    RETURN 1024                 && size of empty ndx file, any key size
  20. ENDIF
  21.  
  22. maxitem  = INT( 504 / (keylen + 8 ) )    && maximum items per node
  23. b_nodes  = ( last_recno / maxitem )      && nodes per branch
  24.  
  25. * Calculate number of nodes in tree
  26. node_cnt = b_nodes + 2 
  27. maxitem  = maxitem + 1
  28. DO WHILE ( b_nodes > maxitem )
  29.    b_nodes  = INT(( b_nodes - 1 ) / maxitem ) + 1   
  30.    node_cnt = ( node_cnt + b_nodes )
  31. ENDDO
  32.  
  33. RETURN ( INT(node_cnt * 512) )
  34.  
  35. * return statement is based on this algorithm:
  36. * maxitem            The number of key entries per a node.
  37. * b_nodes            The number of nodes on 1 branch of the tree.
  38. * node_cnt           This is calculated as nodes on the tree are counted
  39. *                    in the DO WHILE loop.  The loop counts all nodes on 
  40. *                    the tree.  
  41. * (node_cnt * 512)   512 bytes per node.
  42.  
  43. * eofunc ndxsize
  44.  
  45.